﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using HotelManager.Data_Transfer_Layer;
using HotelManager.Business_Logic_Layer;

namespace HotelManager
{
    public partial class ThemKhachHang : Form
    {
        khachhangBLO kh_blo;
        int option;

        public ThemKhachHang()
        {
            InitializeComponent();
            kh_blo = new khachhangBLO();
            option=0;
        }

        public string truyendata_tenkh
        {
            set{txtTenKH.Text = value;}
        }
        public string truyendata_cmnd
        {
            set{txtCMND.Text = value;}
        }
        public string truyendata_sodt
        { 
            set { txtDienThoai.Text = value; }
        }
        public string truyendata_gioitinh
        {
            set { cbbGioitinh.Text = value; }
        }
        public int truyendata_option
        {
            set { option = value; }
        }
        public string truyendata_id
        {
            set { lblID.Text = value; }
        }

        private void bttThem_Click(object sender, EventArgs e)
        {
            try
            {
                if (txtTenKH.Text.Length == 0 || txtDienThoai.Text.Length == 0 || txtCMND.Text.Length == 0 || cbbGioitinh.Text=="")
                {
                    MessageBox.Show("Vui lòng nhập thông tin đầy đủ", "Lỗi");
                    return;
                }
               
                khachhangDTO obj = new khachhangDTO();
                obj.Kh_hoten = txtTenKH.Text;
                obj.Kh_cmnd = txtCMND.Text;
                obj.Kh_gioitinh = cbbGioitinh.Text;
                obj.Kh_sodt = txtDienThoai.Text;
                if (option == 0)
                {
                    kh_blo.Insert(obj);
                    MessageBox.Show("Tạo thông tin khách hàng " + obj.Kh_hoten + " thành công!", "Thông báo");
                }
                else
                {
                    obj.Kh_id = int.Parse(lblID.Text);
                    kh_blo.Update(obj);
                    MessageBox.Show("Thay đổi thông tin khách hàng " + obj.Kh_hoten + " thành công!", "Thông báo");
                }
                if (option == 1)
                {
                    NhanPhong frm_nhanphong = new NhanPhong();
                    frm_nhanphong.truyendulieu_tenkh = txtTenKH.Text;
                    frm_nhanphong.Show();
                }
                this.Close();
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.ToString());
            }
         
        }

        private void btnClose_Click(object sender, EventArgs e)
        {
            if (option == 1)
            {
                NhanPhong frm_nhanphong = new NhanPhong();
                frm_nhanphong.truyendulieu_tenkh = txtTenKH.Text;
               frm_nhanphong.Show();
            }
            this.Close();

        }

        private void txtTenKH_TextChanged(object sender, EventArgs e)
        {

        }
        private void txtDienThoai_TextChanged(object sender, EventArgs e)
        {

        }
        private void txtCMND_TextChanged(object sender, EventArgs e)
        {

        }
        private void txtDienThoai_KeyPress(object sender, KeyPressEventArgs e)
        {
            if (!Char.IsDigit(e.KeyChar) && !Char.IsControl(e.KeyChar))
            {
                e.Handled = true;
            }
        }

        private void txtCMND_KeyPress(object sender, KeyPressEventArgs e)
        {
            if (!Char.IsDigit(e.KeyChar) && !Char.IsControl(e.KeyChar))
            {
                e.Handled = true;
            }
        }

        private void cbbGioitinh_SelectedIndexChanged(object sender, EventArgs e)
        {

        }
    }
}
